package com.zzh.tree;

public class No700_searchBST {
    public static void main(String[] args) {
        TreeNode root = new TreeNode(5);
        root.left = new TreeNode(1);
        root.right = new TreeNode(7);
        root.right.left = new TreeNode(6);
        root.right.right = new TreeNode(8);
        No700Solution solution = new No700Solution();
        TreeNode treeNode = solution.searchBST(root, 9);
        TreeNode.printTree(treeNode);

    }
}

class No700Solution {
    public TreeNode searchBST(TreeNode root, int val) {
        if (root==null){
            return null;
        }
        if (root.val==val) {
            return root;
        }else if (root.val<val){
            return searchBST(root.right,val);
        }else {
            return searchBST(root.left,val);
        }
    }
}
